package com.project.class3_30;

import com.lovo.netCRM.component.LovoImageLabel;
import com.lovo.netCRM.component.LovoLabel;

import javax.swing.*;

public class ThreadFrame extends JFrame implements Runnable{
    private LovoImageLabel photo =new LovoImageLabel(50,50,220,300,this,
            "D:\\手机图片/头像/girl.jpg");
    public ThreadFrame(){
        this.setLayout(null);

        this.setSize(800,500);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        //启动线程
        new Thread(this).start();
    }

    public static void main(String[] args) {
        new ThreadFrame();
    }
    private int speed = 5;
    @Override
    public void run() {
        while (true){
        //得到当前图片的X，Yz坐标
            int x= photo.getX();
            int y= photo.getY();
            if (x>580|| x<0){
                speed*=-1;
            }
            //设置图片的坐标
           photo.setLocation(x+speed,y);

            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
